describe("MoveWhenController in SG", function() {

    var controller = null;
    var currentTransfer = null;
    var objE = null;

    beforeEach(function() {
        currentTransfer = App.BaseTransfer.create({
            fromAccount: null,
            currencyCode: null,
            isRecurring: false,
            isPostDateAllowed: true,
            transferDate: '2013-03-13T11:12:01.675+0800',
            toAccount: App.BaseAccount.create({
                currencyCode: 'SGD'
            })
        });

        objE = new BreezeException({
            errorCode: 123,
            errorMessage: 'error'
        });

        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        var t_moveHolderCtrl = App.MoveHolderController.create();
        App.MoveWhenController.reopen({

            init: function() {
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
                this.set('controllers.moveHolder', t_moveHolderCtrl);
            }

        });

        controller = App.MoveWhenController.create();
    });

    describe("continueAction method", function() {

        beforeEach(function() {
            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(currentTransfer);
            controller.prepareController();
        });

        it("Transfer is CrossTransfer", function() {
            currentTransfer.set('isCrossTransfer', true);
            spyOn(controller, 'showLoading');
            spyOn(App.api_transfer, 'getFxRate');

            controller.continueAction();

            expect(controller.showLoading).toHaveBeenCalled();
            expect(App.api_transfer.getFxRate).toHaveBeenCalled();
        });

        it("Transfer isn't CrossTransfer", function() {
            currentTransfer.set('isCrossTransfer', false);
            spyOn(controller, 'transitionTo');

            controller.continueAction();

            expect(controller.transitionTo).toHaveBeenCalledWith('move.confirm');
        });

    });

    describe("getFxRateCallback method", function() {

        var fxRateObj = {
            buyRate: 1.2,
            transactionToAmount: 10001
        };

        beforeEach(function() {
            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(currentTransfer);
            controller.prepareController();
        });

        it("Callback haven't error", function() {
            spyOn(controller, 'hideLoading');
            spyOn(controller, 'transitionTo');

            controller.getFxRateCallback(fxRateObj, null);

            expect(controller.get('transfer').get('indicativeExchangeRate')).toEqual(fxRateObj.buyRate);
            expect(controller.get('transfer').get('exchangeCurrencyCode')).toEqual(currentTransfer.toAccount.currencyCode);
            expect(controller.get('transfer').get('equivalentAmount')).toEqual(fxRateObj.transactionToAmount);
            expect(controller.hideLoading).toHaveBeenCalled();
            expect(controller.transitionTo).toHaveBeenCalledWith('move.confirm');
        });

        it("Callback have error", function() {

            spyOn(controller, 'hideLoading');

            controller.getFxRateCallback(null, objE);

            expect(controller.hideLoading).toHaveBeenCalled();

        });

    });

})